import u from 'updeep'
import request from '../util/request'
import Taro from '@tarojs/taro'

export default {
  namespace: 'enterpriseHandling',
  state: {
    showCellphone: false,
    cellphone: "15006264331",
    imageWidth:1000,
    imageHeight:100
  },
  reducers: {
    updateState(state, {payload}) {
      return u(payload, state);
    }
  },
  effects: {
    * addView({payload = {}}, {select, put, call}) {

      let url = "/service/view/addView"
      const {data} = yield call(request, {
        url: SERVERURL + url,
        method: 'post',
        data: {
          type: "organization"
        }
      })

      if (data && data === "unauthc") {
        Taro.navigateTo({
          url: `/pages/login/index`
        })
        Taro.showToast({
          title: ("会话过时"),
          icon: 'none'
        })
      }

      let showCellphone = data.data;

      if (data.code === "000000") {
        yield put({
          type: 'updateState',
          payload: {
            showCellphone: showCellphone
          }
        })
      }
    },
    * loadHasView({payload = {}}, {select, put, call}) {
      let url = "/service/view/hasView"
      const {data} = yield call(request, {
        url: SERVERURL + url,
        method: 'post',
        data: {
          type: "organization"
        }
      })

      let showCellphone = data.data;

      if (data.code === "000000") {
        yield put({
          type: 'updateState',
          payload: {
            showCellphone: showCellphone
          }
        })
      }
    }
  }
}
